package com.hjq.demo.yuliao.fragment

import android.view.*
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.hjq.base.BaseAdapter
import com.hjq.demo.R
import com.hjq.demo.app.AppActivity
import com.hjq.demo.app.TitleBarFragment
import com.hjq.demo.app.vb.AppVbActivity
import com.hjq.demo.app.vb.AppVbFragment
import com.hjq.demo.databinding.FragmentBangdanListBinding
import com.hjq.demo.databinding.StatusFragmentBinding
import com.hjq.demo.ui.adapter.StatusAdapter
import com.hjq.demo.utils.CommonSpaceItemDecoration
import com.hjq.demo.utils.CommonSpaceItemDecoration.LINEARLAYOUT
import com.hjq.demo.yuliao.adapter.BangDanListAdapter
import com.hjq.demo.yuliao.adapter.HomeMainRoomListAdapter
import com.hjq.http.EasyHttp
import com.hjq.widget.layout.WrapRecyclerView
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.OnRefreshListener
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener
import java.util.*

/**
 *
 * @author jiahe
 * 创建日期 2022/2/8
 * 描述 首页榜单列表
 *
 */
class BangDanListFragment : AppVbFragment<AppVbActivity<*>, FragmentBangdanListBinding>(), OnRefreshListener,
    OnItemClickListener {

    companion object {

        fun newInstance(): BangDanListFragment {
            return BangDanListFragment()
        }
    }

    private val recyclerView: WrapRecyclerView? by lazy { findViewById(R.id.rv_status_list) }

    private var adapter: BangDanListAdapter? = null

    override fun initView() {
        adapter = BangDanListAdapter()
        adapter?.setOnItemClickListener(this)

        recyclerView?.layoutManager =object :LinearLayoutManager(getAttachActivity()){
            override fun canScrollVertically(): Boolean {
                return false
            }
        }
        recyclerView?.addItemDecoration(
            CommonSpaceItemDecoration(
                resources.getDimension(R.dimen.dp_0_1).toInt(), true,
                LINEARLAYOUT
            )
        )
        recyclerView?.adapter = adapter

//        val view = LayoutInflater.from(context).inflate(R.layout.layout_bangdan_head, binding.root, false)
//        adapter?.addHeaderView(view)

        binding.rlStatusRefresh.setOnRefreshListener(this)
    }

    override fun initData() {
        getListData(true)
    }

    /**
     * [OnRefreshLoadMoreListener]
     */
    override fun onRefresh(refreshLayout: RefreshLayout) {
        getListData(true)
        postDelayed({
            binding.rlStatusRefresh.finishRefresh()
        }, 1000)
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
        getListData(false)
    }

    private fun getListData(isRefresh: Boolean) {
        val list = mutableListOf<String>()
        list.add("123456")
        list.add("123456")
        list.add("123456")
        list.add("123456")
        list.add("123456")
        list.add("123456")
        adapter?.setNewInstance(list)
    }

}